﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddNav.aspx.cs" Inherits="background.Manager.Config.Navigation.AddNav" %>

<!DOCTYPE html>
<% 
    if(string.IsNullOrEmpty(Request["actionType"])) { Response.Write("缺少actionType参数"); return; }
    if(!new Regex("^(add|update)$").IsMatch(Request["actionType"])) { Response.Write("actionType参数：只能是add或update"); return; }
    if(Request["actionType"].ToString()=="update") {
        if(string.IsNullOrEmpty(Request["id"])) { Response.Write("缺少id参数"); return; }
        if(!new Regex("^\\d+$").IsMatch(Request["id"])) { Response.Write("id参数错误"); return; }
    }
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加导航</title>
    <link href="../../Styles/index.css" rel="stylesheet" />
    <script src="../../Scripts/jquery-1.8.2.min.js"></script>
    <script src="../../Scripts/layer/layer.js"></script>

</head>
<body>
    <div class="top">
        <strong>添加导航</strong>
        <span style="float: right"><a href="javascript:history.back();">
            <img src="../../Images/bak.png" />后退</a></span>
    </div>
    <div class="main">
        <!--表单提交-->
        <div>
            <table border="0" cellpadding="0" cellspacing="0" class="table">
                <tr>
                    <th>所属父分类</th>
                    <td>
                        <select id="nav_parent" class="text">
                            <% System.Data.DataTable ndt= Codes.Navigation.getList("-1", ""); %>
                            <% foreach(System.Data.DataRow nr in ndt.Rows) {%>
                            <option <%=Request["parent"].ToString()==nr["ID"].ToString()?"selected='selected'":"" %> value="<%=nr["ID"] %>"><%=nr["name"] %><%=nr["state"].ToString()=="1"?"":"[禁用]" %></option>
                            <%} %>
                        </select>&nbsp;<a href="NavManager.aspx?type=parent">管理父分类</a> <i>一级导航：相当于1，他的子导航相当于：1-1、1-2、1-3</i>
                    </td>
                </tr>
                <tr>
                    <th>导航名称</th>
                    <td>
                        <input type="text" id="nav_name" class="text" value="" /><i>*</i></td>
                </tr>
                <tr>
                    <th>导航拼音</th>
                    <td>
                        <input type="text" id="nav_pyname" class="text" value="" /><i>系统将此字段作为调用凭证</i></td>
                </tr>
                <tr>
                    <th>链接地址</th>
                    <td>
                        <input type="text" id="nav_url" class="text" value="" /><i>*</i>&nbsp;打开方式：<select id="nav_target" style="width: 90px" class="text">
                            <option value="_blank">新的页面</option>
                            <option value="_self">当前页面</option>
                        </select></td>
                </tr>
                <tr>
                    <th>是否显示</th>
                    <td>
                        <select id="nav_state" style="width: 90px" class="text">
                            <option value="1">显示</option>
                            <option value="0">禁用</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>分组</th>
                    <td>
                        <input type="text" id="nav_group" class="text" value="" /><i>多个分组用空格隔开，方便系统调用</i></td>
                </tr>
                <tr>
                    <th>排序</th>
                    <td>
                        <input type="text" id="nav_order" class="text" value="0" /><i>数字越小越靠前，此排序影响后台配置前后显示顺序</i></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" class="sbtn" value="保存" onclick="submit_save()" /></td>
                </tr>
            </table>
        </div>
    </div>
    <script type="text/javascript">
        function submit_save() {
            var _parent = $("#nav_parent option:selected").val()
            _name = $("#nav_name"),
            _pyname = $("#nav_pyname"),
            _url = $("#nav_url"),
            _target = $("#nav_target option:selected").val(),
            _state = $("#nav_state"),
            _group = $("#nav_group"),
            _order = $("#nav_order");
            if ($.trim(_name.val()).length == 0) { layer.msg("请输入导航名字"); _name.focus(); return; }
            //if ($.trim(_pyname.val()).length == 0) { layer.msg("请输入导航属性名字"); _pyname.focus(); return; }
            if ($.trim(_url.val()).length == 0) { layer.msg("请输入导航链接"); _url.focus(); return; }
            if ($.trim(_order.val()).length > 0) { if (!/^\d+$/.test(_order.val())) { layer.msg("请正确输入排序"); _order.focus(); return; } }
            var data = {
                action: "<%=Request["actionType"]%>",
                parent: _parent,
                name: _name.val(),
                pyname: _pyname.val(),
                url: _url.val(),
                target: _target,
                state: _state.val(),
                group: _group.val(),
                order: _order.val(),
                tag: ""
            }
            if ('<%=Request["actionType"]%>' == 'update') {
                data["id"] = '<%=Request["id"]%>';
            }
            $.post("../Action/NavConfig.ashx", data, function (ret) {
                if (ret) {
                    layer.msg("恭喜您保存成功", { icon: 1, time: 2000 }, function () { window.location.href = "NavManager.aspx?type=son&parent=<%=Request["parent"]%>" })
                } else {
                    layer.msg("对不起保存失败", { icon: 2, time: 2000 })
                }
            })
        }
        function loadData() {
            $.getJSON("../Action/NavConfig.ashx", { action: "getInfo", id: '<%=Request["id"]%>' }, function (resultJson) {
                var json = resultJson[0];
                $("#nav_parent option[value=" + json.parent + "]").attr("selected", "selected");
                $("#nav_name").val(json.name);
                $("#nav_pyname").val(json.pyname);
                $("#nav_url").val(json.url);
                $("#nav_target option[value=" + json.target + "]").attr("selected", "selected");
                $("#nav_state").val(json.state);
                $("#nav_group").val(json.group);
                $("#nav_order").val(json.order);
            })
        }
        <%=string.IsNullOrEmpty(Request["id"])?"":"loadData();"%>
    </script>
    <!--#include file='../../Include/footer.html'-->
</body>
</html>
